package last.code.josephring;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        String[] array = scanner.next().split(",");
        LinkedList<String> list = new LinkedList<>(Arrays.asList(array));

        List<String> result = new ArrayList<>();
        while (list.size() > 1) {// 链表仅剩一个元素时停止
            for (int i = 0; i < m - 1; i++) {// 第 1 ~ m-1 个元素需要从头部移动到尾部
                list.add(list.removeFirst());
            }
            result.add(list.removeFirst());// 第 m 个元素移除到结果列表
        }
        result.add(list.removeFirst());// 移除链表中最后一个元素
        System.out.println(String.join(",", result));
    }
}
